home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
dev
/
c
/
cpost_1_4.lha
/
cpostutl.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-11-17
|
38KB
|
1,310 lines
/*------------------------------------------------------------------
* cpostutl.c : utilities for cPost
*------------------------------------------------------------------
* 11-23-91 originally by Patrick J. Mueller
* 12-03-92 converted from cBook to cPost
*------------------------------------------------------------------*/
#ifdef AMIGA
#define USE_BUILTIN_MATH
#endif /* AMIGA */
#if defined(OPSYS_OS2) || defined(OPSYS_OS2V2)
#define INCL_BASE
#include <os2.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <time.h>
#include "ctok.h"
#include "cpost.h"
#include "tokfile.h"
/*-/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-*/
/*-\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/-*/
/*------------------------------------------------------------------
* compare two file names
*------------------------------------------------------------------*/
int FileNameCompare(
File *file1,
File *file2
)
{
int scmp;
int i;
char *name1;
char *name2;
/*---------------------------------------------------------------
* get the base file names
*---------------------------------------------------------------*/
name1 = malloc(1+strlen(file1->name));
name2 = malloc(1+strlen(file2->name));
if (!name1 || !name2)
cPostError(1,"out of memory!!!");
strcpy(name1,file1->name);
strcpy(name2,file2->name);
if (strchr(name1,'.')) *strchr(name1,'.') = 0;
if (strchr(name2,'.')) *strchr(name2,'.') = 0;
/*---------------------------------------------------------------
* sort each category
*---------------------------------------------------------------*/
for (i=0; i<(int)strlen(info.oSort); i++)
{
/*------------------------------------------------------------
* sort by type
*------------------------------------------------------------*/
if ('T' == info.oSort[i])
{
if (file1->type < file2->type)
{
free(name1);
free(name2);
return -1;
}
if (file1->type > file2->type)
{
free(name1);
free(name2);
return 1;
}
scmp = Stricmp(file1->ext,file2->ext);
if (scmp)
{
free(name1);
free(name2);
return scmp;
}
}
/*------------------------------------------------------------
* sort by name
*------------------------------------------------------------*/
else if ('N' == info.oSort[i])
{
/*---------------------------------------------------------
* sort by name
*---------------------------------------------------------*/
scmp = Stricmp(file1->name,file2->name);
if (scmp)
{
free(name1);
free(name2);
return scmp;
}
}
}
free(name1);
free(name2);
return 0;
}
/*-/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-*/
/*-\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/-*/
/*------------------------------------------------------------------
* compare two strings indirectly
*------------------------------------------------------------------*/
int IdentCompare(
char **str1,
char **str2
)
{
return strcmp(*str1,*str2);
}
/*-/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-*/
/*-\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/-*/
/*------------------------------------------------------------------
* compare two function names
*------------------------------------------------------------------*/
int FunctionNameCompare(
Function *func1,
Function *func2
)
{
int cmp;
cmp = Stricmp(func1->name,func2->name);
if (cmp) return cmp;
cmp = strcmp(func1->name,func2->name);
if (cmp) return cmp;
return 0;
}
/*-/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-*/
/*-\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/-*/
/*------------------------------------------------------------------
* compare two function names (via indirection)
*------------------------------------------------------------------*/
int FunctionNamePtrCompare(
Function **func1,
Function **func2
)
{
return FunctionNameCompare(*func1,*func2);
}
/*-/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-*/
/*-\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/-*/
/*------------------------------------------------------------------
* hash an identifier
*------------------------------------------------------------------*/
int IdentHash(
char **str,
int hashSize
)
{
int hash;
char *c;
for (hash=0, c=*str; *c; c++)
hash +=*c;
return hash % hashSize;
}
/*-/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-*/
/*-\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/-*/
/*------------------------------------------------------------------
* add a file to the list of files
*------------------------------------------------------------------*/
void FileAdd(
Info *info,
List *fileList,
char *name,
char *pathName,
char *fDate,
char *fTime
)
{
File file;
char *type;
char *test;
char *ext;
/*---------------------------------------------------------------
* copy the name in
*---------------------------------------------------------------*/
file.name = malloc(1+strlen(name));
if (NULL == file.name)
cPostError(1,"out of memory!!!");
strcpy(file.name,name);
file.pathName = malloc(1+strlen(name)+strlen(pathName));
if (NULL == file.pathName)
cPostError(1,"out of memory!!!");
strcpy(file.pathName,pathName);
strcat(file.pathName,name);
strcpy(file.date,fDate);
strcpy(file.time,fTime);
/*---------------------------------------------------------------
* get the extension
*---------------------------------------------------------------*/
ext = strchr(file.name,'.');
if (!ext)
file.ext = "";
else
{
ext++;
file.ext = malloc(1+strlen(ext));
if (!file.ext)
cPostError(1,"out of memory!!!");
strcpy(file.ext,ext);
/*------------------------------------------------------------
* remove . and anything following it
*------------------------------------------------------------*/
if (strchr(file.ext,'.'))
*strchr(file.ext,'.') = '\0';
}
/*---------------------------------------------------------------
* default the type to 'other'
*---------------------------------------------------------------*/
file.type = 2;
/*---------------------------------------------------------------
* see if it's an 'H' file
*---------------------------------------------------------------*/
type = malloc(1+strlen(info->oHtype));
if (!type)
cPostError(1,"out of memory!!!");
strcpy(type,info->oHtype);
test = strtok(type,", ");
while (test)
{
if (!Stricmp(file.ext,test))
file.type = 0;
test = strtok(NULL,", ");
}
free(type);
/*---------------------------------------------------------------
* see if it's a 'C' file
*---------------------------------------------------------------*/
type = malloc(1+strlen(info->oCtype));
if (!type)
cPostError(1,"out of memory!!!");
strcpy(type,info->oCtype);
test = strtok(type,", ");
while (test)
{
if (!Stricmp(file.ext,test))
file.type = 1;
test = strtok(NULL,", ");
}
free(type);
/*---------------------------------------------------------------
* set rest of stuff
*---------------------------------------------------------------*/
file.line = NULL;
file.lines = 0L;
file.cline = 0L;
file.tempName = NULL;
file.breakList = NULL;
file.funcDefList = ListCreate(siz